﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ForkCarRelationManager.db;
using System.Data;

namespace ForkCarRelationManager.Business
{
    class CarBI
    {
        //实例化数据操作类
        dbOperate oprate = new dbOperate();
        public DataTable getCarWithId(int CarId)
        {
            String sql = "SELECT client.ClientName,car.Brand,car.CarType,car.Model,car.DeviceNum,car.SerialNum,car.EngineType,car.Insourcing,car.Configure,car.BuyData,car.WorkHour,car.BusinessMan,car.SumHour from CarInfor as car left join ClientInfor as client on car.ClientId = client.ID where car.ID = " + CarId;
            DataTable dt = oprate.GetDate(sql);
            return dt;
        }

        public bool updateCarInfo(int CarId, String Brand, String CarType, String Model, String DeviceNum, String SerialNum, String EnginType, int Insourcing, String Configure, String BuyData, int WorkHour,int sumHour,String person)
        {
            String sql = "UPDATE CarInfor set Brand = '" + Brand + "',CarType = '" + CarType + "',Model = '" + Model + "',DeviceNum = '" + DeviceNum + "',SerialNum = '" + SerialNum + "',EngineType='" + EnginType + "',Insourcing = " + Insourcing + ",Configure = '" + Configure + "',BuyData = '" + BuyData + "',WorkHour = " + WorkHour + ",SumHour = " + sumHour + ",BusinessMan = '"+person + "' where ID = " + CarId;
           return  oprate.UpdateAndInsert(sql);
        }

        /*
         * 保存数据
         * */
        public bool addCarInfo(int clientId, String Brand, String CarType, String Model, String DeviceNum, String SerialNum, String EnginType, int Insourcing, String Configure, String BuyData, int WorkHour,int sunHour,String workPerson)
        {
            String sql = "insert into CarInfor (Brand,CarType,Model,DeviceNum,SerialNum,EngineType,Insourcing,Configure,BuyData,WorkHour,ClientId,SumHour,BusinessMan) values('" + Brand + "','" + CarType + "','" + Model + "','" + DeviceNum + "','" + SerialNum + "','" + EnginType + "'," + Insourcing + ",'" + Configure + "', #" + BuyData + "#," + WorkHour + "," + clientId +","+ sunHour+",'"+workPerson+"')";
            return oprate.UpdateAndInsert(sql);
        }
    }
}
